package com.abc.robot01.vivemodel

import android.util.Log
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.abc.robot01.retrofit.RetrofitService
import com.abc.robot01.retrofit.bean.DesignPackage
import com.abc.robot01.retrofit.bean.HouseType
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

/**
 * 方案详情
 */
class FAXiangQingViewModel : ViewModel() {

    val TAG = "方案详情"

    val name  = mutableStateOf("")

    //风格
    var question4List : List<HouseType> = emptyList()

    // StateFlow to hold the commodity data
    private val _commodity = MutableStateFlow<DesignPackage?>(null)
    val commodity: StateFlow<DesignPackage?> get() = _commodity

    //多图片
    // StateFlow to hold the commodity data
    private val _images = MutableStateFlow<String?>(null)
    val images: StateFlow<String?> get() = _images

     val bigImg = MutableStateFlow<String?>(null)

    private val _detailImg = MutableStateFlow<String?>(null)
    val detailImg: StateFlow<String?> get() = _detailImg

    fun  loadProductDetail(id:String){
        viewModelScope.launch {
//            Log.e(TAG, "风格")
//            val s1 = RetrofitService.instance.getSysDicByType(accessToken = Robot.accessToken  ,type = "STYLE")
//            question4List = s1.data
//            Log.e(TAG, "风格 size:"+s1.data.size)
//            Log.e(TAG, "风格:$s1")

            Log.e(TAG, "方案ID: $id")
//            获取商品详情
            val r = RetrofitService.instance.getDesignPackageById(
                companyId = Robot.companyId,
                userId = Robot.userId,
                accessToken = Robot.accessToken,
                id = id)

            Log.e(TAG, "喜好:"+ r.data.interestName)
            Log.e(TAG, "风格:"+ r.data.styleName)
//            r.data.styleName="欧式,欧式,欧式"
            Log.e(TAG, "标签:"+ r.data.labelName)
//            r.data.labelName="标签1,标签2,标签3"
            _commodity.value = r.data

            bigImg.value=  _commodity.value?.thumbnail

//            Log.e(TAG, "commodityImg:"+r.data.commodityImg?.rotatingImgs)
//            _images.value = r.data.commodityImg?.rotatingImgs.also {
//                if (it != null) {
//                    bigImg.value= it.split(",").component1()
//                }
//            }
//
//            r.data.commodityImg?.detailImgUrl?.let {
//                _detailImg.value = it.also {
//                    Log.e(TAG, "detailImgUrl:$it")
//                }
//            }
//            Log.e(TAG, "thumbnail:"+r.data.thumbnail)


        }
    }
    }





